<template>
  <a-layout>
    <a-layout-header>
      <div class="header">
        <h2>光谷智慧交通管理系统</h2>
        <div class="menu">
          <a-menu mode="horizontal">
            <Public v-if="options.public" />
            <Common v-if="options.common" />
            <Traffic v-if="options.traffic" />
          </a-menu>
        </div>
        <Input />
        <User />
      </div>
    </a-layout-header>
    <a-layout-content><MapView></MapView></a-layout-content>
  </a-layout>
</template>

<script setup>
import { Public, Common, Traffic, MapView, User, Input } from './components'
import { useStore } from 'vuex'
import { onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import $api from '@/request/api'
import { message } from 'ant-design-vue'
const $store = useStore()
const router = useRouter()
const options = JSON.parse(JSON.stringify($store.state.options))
const userinformation = JSON.parse(JSON.stringify($store.state.userinformation))
const id = userinformation.user_id

// 点击事件
const listenClick = () => {
  if (id > 1) {
    $api.requestOther(id).then((res) => {
      const { code, messages } = res
      if (code == 404) {
        message.error(messages)
        router.push({
          path: '/login',
        })
      }
    })
  }
}

// 监听点击
onMounted(() => {
  window.addEventListener('click', listenClick, true)
})
// 解绑监听
onUnmounted(() => {
  window.removeEventListener('click', listenClick, true)
})
</script>

<style lang="stylus" scoped>
.ant-layout-header
  min-height: 70px;
  padding: 0px;
  background-color: #fff;
.header
  display: flex
h2
  width: 18%
  height: 70px
  min-height: 64px
  margin: 0
  font-weight:bold
  text-align: center
  line-height: 70px
.menu
  width: 60%
  height: 70px
.menu
  .ant-menu
    border:none
    line-height:70px
.input
  width: 15%
  height: 70px
  padding:19px 0
.user
  width: 10%
.user
  .ant-menu
    border: none
    line-height: 70px
</style>
